#include "Timer.h"

#ifdef _OS_WINDOWS_
    #include <windows.h>
    #include <winnt.h>
    #include <time.h>
#elif _OS_LINUX_
#elif _OS_MAC_
#endif

Timer::Timer()
{
    m_off=0;
}

Timer::~Timer()
{

}

long long Timer::getTime()
{
#ifdef _OS_WINDOWS_
	static bool isFirst = true;
	static LARGE_INTEGER frequency;
	static LARGE_INTEGER start_counter;
	if (isFirst)
	{
		isFirst = false;
		//get the clock frequency
		QueryPerformanceFrequency(&frequency);
		//init the start counter
		QueryPerformanceCounter(&start_counter);
		return 0;
	}
	LARGE_INTEGER current_counter;
	//get the current counter
	QueryPerformanceCounter(&current_counter);
	return (current_counter.QuadPart-start_counter.QuadPart)*1000/frequency.QuadPart;
#elif _OS_LINUX_
#elif _OS_MAC_
#endif

}

void Timer::sleep(unsigned int ms)
{
#ifdef _OS_WINDOWS_
	Sleep(ms);
#elif _OS_LINUX_
#elif _OS_MAC_
#endif
}

void Timer::begin()
{
	m_off = getTime();
}

long long Timer::end()
{
	return getTime()-m_off;
}
